package IBBB.view;

import IBBB.model.UserMessage;
import IBBB.model.WordStockMessage;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.MapChangeListener;
import javafx.collections.ObservableMap;
import javafx.fxml.FXML;
import javafx.geometry.Insets;
import javafx.scene.control.Button;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.StackPane;

import java.beans.EventHandler;
import java.io.IOException;
import java.util.List;

public class BeginLearn {
    @FXML
    private ScrollPane scrollPane;
    @FXML
    private AnchorPane anchorPane;
    @FXML
    private StackPane contains;
    private SelectWordStock selectWordStockPane;
    private UserMessage userMessages;
    private ObservableMap<StringProperty, List<IntegerProperty>> userSchedule;
    private WordStockMessage wordStockMessage;
    List<ScheduleBox> boxController;

    public void init(UserMessage userMessages, WordStockMessage wordStockMessage) {
        this.userMessages = userMessages;
        this.wordStockMessage = wordStockMessage;
        this.userSchedule = userMessages.getWordStockInfo();
        this.userSchedule.addListener((MapChangeListener<StringProperty, List<IntegerProperty>>) change -> {
            if (change.wasAdded() || change.wasRemoved()) {
                try {
                    selectWordStockPane.initialize();
                } catch (IOException e) {
                    // TODO: handle the exception
                    e.printStackTrace();
                }
            }
        });

        try {
            selectWordStockPane = new SelectWordStock(userMessages, wordStockMessage, contains);
            anchorPane.getChildren().add(selectWordStockPane);
        } catch (IOException exp) {
            //TODO:error to be handled
            System.err.println("error");
        }

    }
}
